package tec.stan.ling.topo.model;

import java.util.LinkedList;
import java.util.List;

import tec.stan.ling.core.notifier.NList;
import tec.stan.ling.core.notifier.Notification;
import tec.stan.ling.core.notifier.impl.NotificationImpl;
import tec.stan.ling.core.top.model.Device;
import tec.stan.ling.core.top.model.Link;
import tec.stan.ling.core.top.model.NEState;
import tec.stan.ling.core.top.model.Subnet;

/**
 * 
 * @author Stan 张新潮
 * @date Apr 13, 2010
 */
public class DeviceImpl extends NodeImpl implements Device {

	private NEState state;

	private List<Link> inputLinks;

	private List<Link> outputLinks;

	public DeviceImpl(int id, Subnet parent) {
		this.id = id;
		this.setParent(parent);
	}

	public DeviceImpl(int id, Subnet parent, String name) {
		this(id, parent);
		this.setName(name);
	}

	@Override
	public NEState getState() {
		return state;
	}

	@Override
	public void serState(NEState state) {
		NEState oldState = this.state;
		this.state = state;
		if (isDeliver()) {
			notify(new NotificationImpl(this, Notification.SET,
					Device.DEVICE_STATE, oldState, oldState));
		}
	}

	@Override
	public List<Link> getInputLinks() {
		if (inputLinks == null) {
			inputLinks = new NList<Link>(new LinkedList<Link>(), DEVICE_INPUT,
					this);
		}
		return inputLinks;
	}

	@Override
	public List<Link> getOutputLinks() {
		if (outputLinks == null) {
			outputLinks = new NList<Link>(new LinkedList<Link>(),
					DEVICE_OUTPUT, this);
		}
		return outputLinks;
	}
}
